const HouseModel = require("../models/house.js");

class HouseController {
  static async default(ctx, next) {
    const { types,page=1,num=20} = ctx.request.body;
    const total = await HouseModel.countDocuments({types})
    const res  = await HouseModel.find({types:types},'_id description price name ImgUrls').limit(num).skip((page-1)*num)
    res.map((item,index)=>{
      item.description = item.description.join(',').substring(0,135)
      item.ImgUrls = item.ImgUrls[0]
    })
    ctx.status = 200
    ctx.body = {
      list:res,
      total
    }
  }
  static async getDetail(ctx){
    const  _id  = ctx.params.id;
    console.log(ctx.params)
    const res = await HouseModel.findById(_id)
    
    ctx.status = 200
    ctx.body = res
  }
}
module.exports = HouseController;
